package logic

import (
	"baidu/modil/mysql"
	"context"

	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpdateLogic) UserUpdate(in *baidurpc.UserUpdateRequest) (*baidurpc.UserUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	mysql.DB.Debug().Where("id=?", in.Id).Find(&user)
	user.Photo = in.Photo
	user.Username = in.Username
	mysql.DB.Debug().Updates(&user)
	return &baidurpc.UserUpdateResponse{
		UserId: int64(user.ID),
	}, nil
}
